package com.pengcheng.taskapplication.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.pengcheng.taskapplication.R;
import com.pengcheng.taskapplication.model.WashTypeModel;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

public class WashTypeAdapter extends BaseAdapter {

	Context context;
	LayoutInflater inflater;
	ArrayList<WashTypeModel> washTypeModels;
	int last_item;
	private int selectedPosition = -1;
	public WashTypeAdapter(Context context, ArrayList<WashTypeModel> washTypeModels){
		this.context = context;
		this.washTypeModels = washTypeModels;
		inflater= LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return washTypeModels.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return washTypeModels.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder  holder = null;
		if(convertView==null){
			convertView = inflater.inflate(R.layout.activity_washtype_item_layout, null);
			holder = new ViewHolder();
			holder.ll_high=(LinearLayout) convertView.findViewById(R.id.ll_high);
			holder.tv_money=(TextView)convertView.findViewById(R.id.tv_money);
			holder.tv_wash_type_name=(TextView)convertView.findViewById(R.id.tv_wash_type_name);
			convertView.setTag(holder);
		}
		else{
			holder=(ViewHolder)convertView.getTag();
		}

		WashTypeModel model= washTypeModels.get(position);
		BigDecimal bg = new BigDecimal(model.getPrice()/100);
		holder.tv_money.setText("￥"+bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
		holder.tv_wash_type_name.setText(model.getOptionname());
		if(selectedPosition == position)
		{
			holder.ll_high.setBackgroundResource(R.drawable.zhifu_bg);
		} else {
			holder.ll_high.setBackgroundResource(R.drawable.zhifu_bg_a);
		}

		return convertView;
	}

	public static class ViewHolder{
		public TextView tv_money;
		public TextView tv_wash_type_name;
		public LinearLayout ll_high;

	}

	public void setSelectedPosition(int position) {
		selectedPosition = position;
	}



}
